package com.heboan.hadoop.mr_homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class MyDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "MyDriver");
        job.setJarByClass(MyDriver.class);

        // map/reduce类
        job.setMapperClass(MyMapper.class);
        job.setReducerClass(MyReducer.class);
        // map输出k, v类型
        job.setMapOutputKeyClass(MyBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        // 最终输出k v类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(MyBean.class);

        // 输入输出路径
        FileInputFormat.setInputPaths(job, new Path("D:/test_hadoop/mr_homework_input"));
        FileOutputFormat.setOutputPath(job, new Path("D:/test_hadoop/mr_homework_output"));

        // 提交任务
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
